<%= javascript_include_tag "zerocms/admin/custom_fields_form" %>
<div class="page-title">
    <h2><span class="fa fa-cog"></span> <%= @field_group.new_record? ? t('zerocms.admin.settings.new_custom_field_group') : "#{t('zerocms.admin.settings.new_custom_field_group')}: #{@field_group.name} "%> </h2>
</div>

<!-- PAGE CONTENT WRAPPER -->
<div class="page-content-wrap" id="zerocms_custom_field_form" data-group_class_name="<%= @field_group.object_class %>,<%= @field_group.objectid %>">
    <div class="row">
        <%= form_for @field_group, as: "custom_field_group", url:{action: @field_group.new_record? ? :create : :update}, html: {class: 'validate-custom-field validate zerocms_ajax_request'} do |f| %>
            <div class="col-md-4">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><%= t('zerocms.admin.settings.details_custom_field_group') %></h3>
                    </div>
                    <div class="panel-body">
                        <%= render partial: 'layouts/zerocms/admin/form_error', locals: {data: @field_group} %>
                        <div class="form-group">
                            <%= f.label t('zerocms.admin.table.name') %><br>
                            <%= f.text_field :name, :class => "form-control required" %>
                        </div>
                        <div class="form-group hidden">
                            <%#= f.label t('zerocms.admin.table.slug') %><br>
                            <%#= f.text_field :slug, :class => "form-control slug", "data-parent" => 'custom_field_group_name' %>
                        </div>
                        <div class="form-group">
                            <%= f.label t('zerocms.admin.custom_field.custom_group_support_multiple', default: 'Support multiple groups?') %><br>
                            <%= f.check_box :is_repeat, :class => "" %>
                        </div>
                        <div class="form-group">
                            <%= f.label t('zerocms.admin.table.description') %><br>
                            <%= f.text_area :description, :class => "form-control" %>
                        </div>
                        <div class="form-group">
                            <%= f.label t('zerocms.admin.settings.where_display_group') %><br>
                            <select id="select_assign_group" name="custom_field_group[assign_group]" class="form-control required">
                                <option value="">&nbsp;</option>
                                <optgroup label="<%= t('zerocms.admin.settings.posts_in') %>">
                                    <% current_site.post_types.each do |pt| pt = pt.decorate; value = "PostType_Post,#{pt.id}" %>
                                        <option value="<%= value %>" data-help="<%= "#{t('zerocms.admin.settings.tooltip.add_custom_field_posts')}"+ pt.the_title %>"><%= pt.the_title %></option>
                                    <% end  %>
                                </optgroup>

                                <optgroup label="<%= t('zerocms.admin.settings.categories_in') %>">
                                    <% current_site.post_types.each do |pt| pt = pt.decorate; value = "PostType_Category,#{pt.id}" %>
                                        <% if pt.manage_categories? %>
                                            <option value="<%= value %>" data-help="<%= "#{t('zerocms.admin.settings.tooltip.add_custom_field_categories')}"+ pt.the_title %>"><%= pt.the_title %></option>
                                        <% end %>
                                    <% end  %>
                                </optgroup>

                                <optgroup label="<%= t('zerocms.admin.settings.post_tags_in', default: 'Post Tags In') %>">
                                    <% current_site.post_types.each do |pt| pt = pt.decorate; value = "PostType_PostTag,#{pt.id}" %>
                                        <% if pt.manage_tags? %>
                                            <option value="<%= value %>" data-help="<%= "#{t('zerocms.admin.settings.tooltip.add_custom_field_tags', default: 'Add Custom Field in Post Tags of ')}"+ pt.the_title %>"><%= pt.the_title %></option>
                                        <% end %>
                                    <% end  %>
                                </optgroup>

                                <optgroup label="<%= t('zerocms.admin.settings.others') %>">
                                    <% value = "User,#{current_site.id}" %>
                                    <option value="<%= value %>" data-help="<%= t('zerocms.admin.settings.tooltip.add_custom_field_users') %>"><%= t('zerocms.admin.sidebar.users') %></option>
                                    <% value = "Site,#{current_site.id}" %>
                                    <option value="<%= value %>" data-help="<%= t('zerocms.admin.settings.tooltip.add_custom_field_sites') %>"><%= t('zerocms.admin.sidebar.site_settings') %></option>
                                    <% f_args={models: @_extra_models_for_fields || []}; hooks_run('custom_field_custom_models', f_args); f_args[:models].each do |model| %>
                                        <% value = "#{model.name},#{current_site.id}" %>
                                        <option value="<%= value %>" data-help=""><%= model.name %></option><%= model.name %>
                                    <% end %>
                                </optgroup>

                                <optgroup label="<%= t('zerocms.admin.sidebar.themes') %>">
                                    <option value="Theme,<%= current_theme.id %>" data-help=""><%= current_theme.name %></option>
                                </optgroup>

                                <optgroup label="<%= t('zerocms.admin.sidebar.menus') %>">
                                    <% current_site.nav_menus.each do |menu| %>
                                        <option value="NavMenu,<%= menu.id %>" data-help=""><%= menu.name %></option>
                                    <% end %>
                                </optgroup>

                                <!--optgroup label="<%#= t('zerocms.admin.sidebar.widgets') %>">
                                    <%# current_site.widgets.each do |widget| %>
                                        <%# value = "#{widget.class.name},#{widget.id}" %>
                                        <option value="<%#= value %>" data-help="<%#= "#{t('zerocms.admin.settings.tooltip.add_custom_field_widget')}"+ widget.name %>"><%#= widget.name %></option>
                                    <%# end %>
                                </optgroup -->
                                <option value="_post_simple" >Select Post Simple</option>
                            </select>
                            <select id="select_post_simple" name="custom_field_group[assign_group]" class="form-control required" style="display: none" disabled>
                                <% current_site.post_types.each do |pt| pt = pt.decorate %>
                                    <optgroup label="<%= pt.the_title %>">
                                        <% pt.posts.visible_frontend.each do |post| value = "#{post.class.name},#{post.id}".parseZerocmsClass; post = post.decorate %>
                                            <option value="<%= value %>" data-help="<%= "#{t('zerocms.admin.settings.tooltip.add_custom_field_posts')}"+ post.the_title %>"><%= post.the_title %></option>
                                        <% end %>
                                    </optgroup>
                                <% end %>
                            </select>
                            <input id="select_assign_group_caption" type="hidden" name="custom_field_group[caption]"/>
                            <div id="select_assign_group_help"></div>
                        </div>
                    </div>
                    <div class="panel-footer">
                        <a class="btn btn-default" role="back" href="<%= url_for action: :index %>"><%= t('zerocms.admin.button.back') %></a>
                        <button class="btn btn-primary pull-right" type="submit"><%= t('zerocms.admin.button.submit') %></button>
                    </div>
                </div>
            </div>
            <div class="col-md-5">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><%= t('zerocms.admin.settings.fields') %></h3>
                    </div>
                    <div class="panel-body padding-0">
                        <% fields =  @field_group.new_record? ? [] : @field_group.fields %>
                        <ul id="sortable-fields" class="clear list-unstyled">
                            <% fields.each do |field| @item_value = field; @item_options_value = field.options; @key = field.options[:field_key] %>
                                <li class="item">
                                    <%= render "get_items" %>
                                </li>
                            <% end  %>
                        </ul>
                    </div>
                    <div class="panel-footer hidden">
                        <a class="btn btn-default" role="back" href="<%= url_for action: :index %>"><%= t('zerocms.admin.button.back') %></a>
                        <button class="btn btn-primary pull-right" type="submit"><%= t('zerocms.admin.button.submit') %></button>
                    </div>
                </div>
            </div>

            <div class="col-md-3">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><%= t('zerocms.admin.settings.available_fields')%></h3>
                    </div>
                    <div class="panel-body">
                        <div id="content-items-default" class="form-group input-group-sm">
                            <% zerocms_custom_field_elements.each do |i,item| %>
                                <% next if item[:key] == "select_eval" %>
                                <a id="item-<%= item[:key] %>" class="btn btn-default" href="<%= get_items_zerocms_admin_settings_custom_fields_path(item[:key]) %>" style="margin-bottom: 4px"><%= item[:label] %></a>
                            <% end %>
                        </div>
                    </div>
                    <div class="panel-footer hidden">
                        <a class="btn btn-default" role="back" href="<%= url_for action: :index %>"><%= t('zerocms.admin.button.back') %></a>
                        <button class="btn btn-primary pull-right" type="submit"><%= t('zerocms.admin.button.submit') %></button>
                    </div>
                </div>
            </div>
        <% end %>
    </div>
</div>



